<?php

namespace App\Http\Controllers\Backend;
use App\Common\ResponseCode;
use App\Http\Controllers\BaseController;
use App\Http\Middleware\AdminAuth;
use App\Params\Backend\BrandListParams;
use App\Params\Backend\BrandUpdateParam;
use App\Services\Goods\BrandService;
use App\Traits\VerifyRequestParam;
use Illuminate\Http\Request;
/**
 * 商品品牌控制器
 *
 * @package App\Http\Controllers\H5
 * @author WangBin
 * @date 2021-06/11
 */
class BrandController extends BaseController
{
    use VerifyRequestParam;

    public function __construct()
    {
        $this->middleware(AdminAuth::class);
    }

    /**
     * 保存品牌
     *
     * @param Request $request
     * @throws
     * @return
     */
    public function update(Request $request)
    {
        $param = BrandUpdateParam::create();
        $ret = BrandService::getInstance()->update($param);
        if($ret) {
            return $this->success(['brand_id' => $ret]);
        }
        return $this->fail(ResponseCode::BRAND_UPDATE_FAIL);
    }

    /**
     * 商品品牌列表
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws
     */
    public function getList(Request $request)
    {
        $param = BrandListParams::create();
        $brands = BrandService::getInstance()->getList($param);
        return $this->success($brands);
    }

    /**
     * 品牌详情
     *
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\BusinessException
     */
    public function get()
    {
        return $this->success(BrandService::getInstance()->get($this->verifyInteger('id')));
    }
}